package bidsanity

import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class ListingIntegrationTests {

    def s = new Customer(emailAddress: 'seller@example.org', password: "testing")
    def w = new Customer(emailAddress: 'winner@example.org', password: "testing")

    @Before
    void setUp() {
        // Setup logic here
        s.save()
        w.save()

    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testMultipleBids() {
        def l = new Listing(
                name: 'TestListing',
                endDate: new Date() + 10,
                startingBidPrice: 1.0D,
                description: 'a test listing',
                seller: s,
                winner: w)
        l.save(failOnError: false, validate: true, flush: true)
        Assert.assertFalse l.hasErrors()

        Assert.assertNotNull l.name
        Assert.assertNotNull l.endDate
        Assert.assertNotNull l.startingBidPrice
        Assert.assertNotNull l.description
        Assert.assertNotNull l.seller
        Assert.assertNotNull l.winner
        Assert.assertEquals Listing.list().size(), 1
        Assert.assertTrue(Listing.findAllBySeller(s).size() > 0)
    }
}
